{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EX1\n",
    "a = Louis card number is 0766310\n",
    "\n",
    "b = Tom card number is 0981101\n",
    "\n",
    "Can you extract the student card number? Print out the format as follows:\n",
    "\n",
    "Louis:0766310\n",
    "\n",
    "Tom:0981101"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Louis:0766310\n",
      "Louis:0766310\n"
     ]
    }
   ],
   "source": [
    "a = \"Louis card = 0766310\"\n",
    "b = \"Tom card = 0981101\"\n",
    "print (a[0:5] +':'+ a[13:len(a)])\n",
    "# other way? \n",
    "\n",
    "a= 'Louis card = 0766310'\n",
    "l = a.split (\" \")\n",
    "print (l[0]+':'+ l[3])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2\n",
    "\n",
    "Delete the numbers greater than 100 and sort them from small to large\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 7, 12, 32, 54, 67, 88]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L = [6,7,88,191,32,330,12,54,901,104,3,67,111,1479,0]\n",
    "result = []  # push the number that is smaller than 100\n",
    "# method 1：\n",
    "for l in L:\n",
    "    if l<100:\n",
    "        result.append(l)\n",
    "result.sort()\n",
    "result\n",
    "        \n",
    "      # use  ‘append’function \n",
    "# sort \n",
    "\n",
    "# do you have other way to slove the problem?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 7, 12, 32, 54, 67, 88]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a list 'L' containing 15 numbers\n",
    "L = [6,7,88,191,32,330,12,54,901,104,3,67,111,1479,0]\n",
    "\n",
    "# Define an empty list named 'result'\n",
    "result = []\n",
    "\n",
    "# Iterate over each element of 'L' and append it to 'result' if it is less than 100\n",
    "for l in L:\n",
    "    if l < 100:          # If the element is less than 100\n",
    "        result.append(l) # Append it to the 'result' list using the 'append()' method\n",
    "\n",
    "# Sort the 'result' list in ascending order\n",
    "result.sort()\n",
    "\n",
    "# Output the sorted 'result' list consisting of numbers less than 100 in ascending order\n",
    "result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(...) method of builtins.list instance\n",
      "    L.append(object) -> None -- append object to end\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "help (result.append)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l=[1,2]\n",
    "l.append(3)\n",
    "l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex3\n",
    "\n",
    "Problem Description:\n",
    "\n",
    "Given an integer, determine if it is a palindrome. An integer is a palindrome when it reads the same backward as forward.\n",
    "\n",
    "For example, 121 is palindrome while 123 is not.\n",
    "\n",
    "Example 1:\n",
    "\n",
    "Input: 121\n",
    "\n",
    "Output: true\n",
    "\n",
    "Example 2:\n",
    "\n",
    "Input: 122\n",
    "\n",
    "Output: false\n",
    "\n",
    "Explanation: From left to right, it reads 122. From right to left, it becomes 221. Therefore it is not a palindrome."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['8', '7', '6', '7', '8']\n",
      "true\n"
     ]
    }
   ],
   "source": [
    "\n",
    "s= '87678'\n",
    "l=list(s)\n",
    "l.reverse()# reverse = reversing things                                  # == = equal like maths\n",
    "\n",
    "print(l)\n",
    "f=\"\".join(l)# join = joining the int or str together\n",
    "if s==f:\n",
    "    print(\"true\")\n",
    "else:\n",
    "    print(\"false\")\n",
    "\n",
    "\n",
    "# you don't have to put the inverted commas for true and false you just need to type it in capital letters for the first letter.\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
